const positionAddTpl = require('../views/position-add.html')


const positionAddController = {
  render({res,router}){
    res.render(positionAddTpl)

    //点击返回按钮，直接返回上一级

    $('#app-add-back').on('click',()=>{
      router.back()
    })

    $('#app-add-save').on('click',()=>{
      this.doSubmit()
    })
  },
  doSubmit(){
    //点击保存进行ajax提交
    const companyName = $('#companyName').val(),
          positionName = $('#positionName').val(),
          city = $('#city').val(),
          salary = $('#salary').val(),
          degree = $('#degree').val(),
          experience = $('#experience').val(),
          description = $('#description').val(),
          createTime = Date.now() //获取的是时间戳
    $.ajax({
      url: '/api/position/add',//暴露的接口
      type: 'POST',
      data: {
        companyName,
        positionName,
        city,
        salary,
        degree,
        experience,
        description,
        createTime
      },
      success(res){
        console.log( res )//后台返回结果
      }
    })
  }
}


module.exports = positionAddController